﻿using UnityEngine;

namespace Super
{
	public class BaseSingle<T> : MonoBehaviour where T : BaseSingle<T>
	{
		public virtual void OnInit() {}

		private static T ins;
		public static T Ins
		{
			get
			{
				if (ins == null)
					ins = FindObjectOfType(typeof(T)) as T;
				if (ins == null)
				{
					Transform parent = GameUtil.GetOrCreatSceneRoot("ManagerBox", DefaultConfig.managerBox);
					GameObject go = new GameObject(typeof(T).Name);
					go.transform.SetParent(parent);
					go.transform.position = Vector3.zero;
					ins = go.AddComponent<T>();
				}
				return ins;
			}
		}
	}

}
